/**
 * Created by forcht on 2018/5/16.
 */
public class Solution {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode head = null;
        ListNode tail = null;
        int c = 0;
        while (l1 != null || l2 != null||c!=0) {
            if (l1!=null){
                c+=l1.val;
                l1=l1.next;
            }
            if (l2!=null){
                c+=l2.val;
                l2=l2.next;
            }
            ListNode listNode=new ListNode(c%10);
            if(head==null){
                head=listNode;
                tail=head;
            }else {
                tail.next=listNode;
                tail=listNode;
            }
            c/=10;
        }
        return head;
    }
}

class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
        next = null;
    }
}

